/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.approval.controller;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.icinfo.cloud.common.core.config.CfRedisRepository;
import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.common.security.util.UserUtil;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.enums.BusinessContextKeyEnum;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.common.utils.BaseUtil;
import com.icinfo.cloud.provider.common.utils.BusinessContextUtil;
import com.icinfo.cloud.provider.logs.model.LogsCaseDocumentSerialRecord;
import com.icinfo.cloud.provider.logs.service.ILogsCaseDocumentSerialRecordService;
import com.icinfo.cloud.provider.punish.approval.dto.*;
import com.icinfo.cloud.provider.punish.approval.service.ICaseApprovalWaitRecordService;
import com.icinfo.cloud.provider.punish.approval.vo.*;
import com.icinfo.cloud.provider.punish.config.model.ConfigBusiParamDocumentInfo;
import com.icinfo.cloud.provider.punish.config.service.IConfigBusiParamDocumentInfoService;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseQueryDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.CaseMainInfoMapper;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.CaseMainInfo;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseMainInfoService;
import com.icinfo.cloud.xzcf.provider.member.userinfo.dto.UserDTO;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import com.icinfo.framework.tools.utils.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 描述: 案件文书待审批记录表 case_approval_wait_record 对应的Controller类.<br>
 * 待审批 controller
 *
 * @author 程亚运
 * @date 2022年02月15日
 */
@RestController
@RequestMapping("/waitAudit")
public class CaseApprovalWaitRecordController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(CaseApprovalWaitRecordController.class);

    @Autowired
    private ICaseApprovalWaitRecordService caseApprovalWaitRecordService;
    @Autowired
    private CaseMainInfoMapper caseMainInfoMapper;
    @Resource
    private CfRedisRepository cfRedisRepository;
    @Autowired
    private ICaseMainInfoService caseMainInfoService;
    @Resource
    private ILogsCaseDocumentSerialRecordService logsCaseDocumentSerialRecordService;
    @Resource
    private IConfigBusiParamDocumentInfoService configBusiParamDocumentInfoService;

    /**
     *
     * ====================================================================审批相关=========================================================================
     *
     */

    /**
     * 查询待审批列表
     * @param auditQueryPageDto
     * @return
     */
    @PostMapping("/getWaitAuditList")
    public Result<PageResponse<AuditInfoListVo>> getWaitAuditList(@Validated @RequestBody AuditQueryPageDto auditQueryPageDto){
        // 查询待审批表 根据用户id 查询 case_approval_wait_record
        return Result.success("success",new PageResponse(caseApprovalWaitRecordService.getWaitList(auditQueryPageDto)));
    }

    /**
     * 查询待审批页 每个颜色时效案件数量
     * @param
     * @return
     */
    @PostMapping("/getEachColorNum")
    public Result<WaitPageEachColorNumVo> getEachColorNum(@RequestBody AuditQueryPageDto auditQueryPageDto){
        // 查询当前用户
        // 根据当前用户查询待审批表
        return Result.success("success",caseApprovalWaitRecordService.getEachColorNum(auditQueryPageDto));
    }

    /**
     * 描述: 工作台-查询待审批列表,增加类型区分
     *
     * @param auditQueryPageDto
     * @return Result
     * @author zhanghongqiang
     * @Date 2022/8/29
     */
    @PostMapping("/readWaitAuditList")
    public Result<PageResponse<AuditInfoListVo>> readWaitAuditList(@Validated @RequestBody AuditQueryPageDto auditQueryPageDto) {
        // 查询待审批表 根据用户id 查询 case_approval_wait_record
        return Result.success("success", new PageResponse(caseApprovalWaitRecordService.getWaitAuditList(auditQueryPageDto)));
    }

    /**
     * 描述: 工作台-查询待审批页 每个颜色时效案件数量
     *
     * @param auditQueryPageDto
     * @return com.icinfo.framework.common.web.Result
     * @author zhanghongqiang
     * @Date 2022/8/30
     */
    @PostMapping("/readApprovedColorNum")
    public Result<WaitPageEachColorNumVo> readApprovedColorNum(@RequestBody AuditQueryPageDto auditQueryPageDto) {
        // 查询当前用户
        // 根据当前用户查询待审批表
        return Result.success("success", caseApprovalWaitRecordService.getApprovedColorNum(auditQueryPageDto));
    }


    /**
     * 审批通过
     * @param
     * @return
     */
    @PostMapping("/doAgreeAudit")
    public Result doAgreeAudit(@Validated @RequestBody ApprovalAgreeAuditDto approvalAuditDto){
        //读取当前用户，当前审批环节，校验角色权限，根据审批结果，流转下个节点
        // 校验审批权限 （不做了，能查到，数据存入时已校验处理）
        // 审批结果写入 case_approval_complete_record 已完成审批表 ，
        // 审批通过 写入下个节点  写入 待审批 case_approval_wait_record
        // 中间需要调用member服务 查询审批人姓名
        //设置文号回归标识 -- 用于文书审批异常文号回归
        String caseDocumentSerialKey = "PUNISH:EXCEPTION:DOC:NUMBER:" + BaseUtil.createUid();
        approvalAuditDto.setExceptionCaseDocumentSerialKey(caseDocumentSerialKey);
        try {
            if(caseApprovalWaitRecordService.doAgreeAudit(approvalAuditDto).size() == 1){
                return Result.success("操作成功！");
            }
        } catch (Exception e) {
//            String exceptionSerialStr = cfRedisRepository.get(caseDocumentSerialKey);
            String exceptionSerialStr = BusinessContextUtil.get(BusinessContextKeyEnum.DOCUMENT_NUMBER_REGRESSION_IDENTIFICATION_CODE, String.class);
            if (ObjectUtil.isNotEmpty(exceptionSerialStr)) {
                List<Map> docNumberList = JSON.parseArray(exceptionSerialStr, Map.class);
                //审批文书跳号问题优化
                //该方法一旦发生异常，且生成了文号的情况下，则触发文号回归文号池的策略（当前文号池先以表进行存储）
                if(ObjectUtil.isNotEmpty(docNumberList)){
                    LogsCaseDocumentSerialRecord logsCaseDocumentSerialRecord = new LogsCaseDocumentSerialRecord();
                    logsCaseDocumentSerialRecord.setBusiId(approvalAuditDto.getCaseId());
                    for (Map<String, Object> docNumberExcepMap : docNumberList){
                        //序列的文书目录编码处理
                        String serialCatalogCode1 = docNumberExcepMap.get("serialCatalogCode").toString();
                        ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = configBusiParamDocumentInfoService.getDetailByDocumentCatalogCode(serialCatalogCode1);
                        if ("4".equals(configBusiParamDocumentInfo.getDocumentNumberSerialType())) {
                            //4-与某文书使用相同序列
                            serialCatalogCode1 = configBusiParamDocumentInfo.getDocumentNumberMatchCatalogCode();
                        }
                        logsCaseDocumentSerialRecord.setDocumentCatalogCode(serialCatalogCode1);
                        logsCaseDocumentSerialRecord.setSerial(Long.valueOf(docNumberExcepMap.get("serialNumber").toString()));
                        logsCaseDocumentSerialRecordService.modLogsCaseDocumentSerialRecordException(logsCaseDocumentSerialRecord);
                    }
                }
            }
            if(e instanceof BusinessException){
                throw new BusinessException(e.getMessage());
            }else{
                throw e;
            }
        } finally {
            BusinessContextUtil.remove();
            //删除异常文号数据
//            cfRedisRepository.del(caseDocumentSerialKey);
        }

      /*  String ugl = "unGetLock";
        if (caseApprovalWaitRecordService.doAgreeAudit(approvalAuditDto).get(ugl) != null){
            return Result.error(caseApprovalWaitRecordService.doAgreeAudit(approvalAuditDto).get(ugl).toString());
        }*/

        return Result.error("操作失败！");
    }

    @PostMapping("/doAgreeAuditNew")
    public Result doAgreeAuditNew(@Validated @RequestBody ApprovalAgreeAuditDto approvalAuditDto){
        if(caseApprovalWaitRecordService.doAgreeAuditNew(approvalAuditDto).size() == 1){
            return Result.success("操作成功！");
        }
        return Result.error("操作失败！");
    }


    /**
     * 审批退回
     * @param
     * @return
     */
    @PostMapping("/doReturnAudit")
    public Result doReturnAudit(@Validated @RequestBody ApprovalReturnlAuditDto approvalAuditDto){
        //读取当前用户，当前审批环节，校验角色权限，根据审批结果，流转下个节点
        // 校验审批权限 （不做了，能查到，数据存入时已校验处理）
        // 审批结果写入 case_approval_complete_record 已完成审批表，
        // 审批通过 写入下个节点  写入 待审批 case_approval_wait_record
        // 中间需要调用member服务 查询审批人姓名
        if(caseApprovalWaitRecordService.doReturnAudit(approvalAuditDto).size() >= 1){
            return Result.success("操作成功！");
        }

       /* String ugl = "unGetLock";
        if (caseApprovalWaitRecordService.doReturnAudit(approvalAuditDto).get(ugl) != null){
            return Result.error(caseApprovalWaitRecordService.doReturnAudit(approvalAuditDto).get(ugl).toString());
        }*/
        return Result.error("操作失败！");
    }

    /**
     * 通用提交审批接口，该文书需要审批调用
     * @param
     * @return
     */
    @PostMapping("/documentGeneralSubmit")
    public Result documentGeneralSubmit(@Validated @RequestBody ApprovalGeneralSubmitDto dto){
        Map<String,Object> result = caseApprovalWaitRecordService.documentGeneralSubmit(dto.getCaseId(),dto.getDocumentCatalogCode(),dto.getNextHandler(),dto.getOpinion(),dto.getPartyId(),dto.getCaseAssistId(),dto.getIsAutoApproval(),dto.getAutoTime(),dto.getDocId(),dto.getIsEditApproval());
        if(result.size() > 1){
            return Result.success("操作成功！",result);
        }
        return Result.error("操作失败！");
    }
    @PostMapping("/documentGeneralSubmitNew")
    public Result documentGeneralSubmitNew(@Validated @RequestBody ApprovalGeneralSubmitDto dto){
        Map<String,Object> result = caseApprovalWaitRecordService.documentGeneralSubmitNew(dto);
        if(result.size() > 1){
            return Result.success("操作成功！",result);
        }
        return Result.error("操作失败！");
    }
    /**
     * 提交自动审批接口，该文书需要审批调用
     * @param
     * @return
     */
    @PostMapping("/documentGeneralSubmitAuto")
    public Result documentGeneralSubmitAuto(@Validated @RequestBody ApprovalGeneralSubmitDto dto){
        cfRedisRepository.set("IS_APPROVAL_AUTO_PASS"+dto.getCaseId(),"false");
        Map<String,Object> result = caseApprovalWaitRecordService.documentGeneralSubmitAuto(dto.getCaseId(),dto.getDocumentCatalogCode(),dto.getNextHandler(),dto.getOpinion(),dto.getPartyId(),dto.getCaseAssistId(),dto.getIsAutoApproval(),dto.getAutoTime());
        String closeSignal= MapUtils.getString(result,"closeSignal","");
        if(!"CLOSE-TRIGGER-APPROVAL".equals(closeSignal)){
            Result.error("操作失败！");
        }
        ApprovalAgreeAuditDto approvalAgreeAuditDto = caseApprovalWaitRecordService.getApprovalAgreeAuditDto(dto);
        //approvalAgreeAuditDto.setNowHandler(dto.getNextHandler());
        for (int i=0;i<4;i++) {
            //如果下个环节是自动审批
            if(Constant.STRING_1.equals(approvalAgreeAuditDto.getIsAutoApproval())) {
                Long autoTime = Long.valueOf(approvalAgreeAuditDto.getAutoTime());
                if(autoTime>2){
                    autoTime=autoTime-2;
                }
                try {
                    Thread.sleep(autoTime * 1000);
                    //Thread.sleep(autoTime);
                    Map<String, Object> agreeResult = caseApprovalWaitRecordService.doAgreeAuditAuto(approvalAgreeAuditDto);
                    closeSignal = MapUtils.getString(agreeResult, "closeSignal", "");
                    result.put("closeSignal", "CLOSE-TRIGGER-APPROVAL-PASS");
                    if ("CLOSE-TRIGGER-APPROVAL-PASS".equals(closeSignal)) {
                        cfRedisRepository.set("IS_APPROVAL_AUTO_PASS" + dto.getCaseId(), "true");
                        break;
                    }
                    String nowHandler = approvalAgreeAuditDto.getNextHandler();
                    approvalAgreeAuditDto = caseApprovalWaitRecordService.getApprovalAgreeAuditDto(dto);
                    approvalAgreeAuditDto.setNowHandler(nowHandler);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }else{
                cfRedisRepository.set("IS_APPROVAL_AUTO_PASS"+dto.getCaseId(),"true");
                break;
            }
        }
        return Result.success("操作成功！",result);
    }

    /**
     * 通用提交审批接口，该文书需要审批调用(裁执分离)
     * @param
     * @return
     */
    @PostMapping("/documentGeneralSubmitWithExecute")
    public Result documentGeneralSubmitWithExecute(@Validated @RequestBody ApprovalGeneralSubmitDto dto){
        Map<String,Object> result = caseApprovalWaitRecordService.documentGeneralSubmitWithExecute(dto.getCaseId(),dto.getDocumentCatalogCode(),dto.getNextHandler(),dto.getOpinion(),dto.getPartyId());
        if(result.size() > 1){
            return Result.success("操作成功！");
        }
        return Result.error("操作失败！");
    }

    /**
     * 查询下个节点处理人员列表
     * 案件caseId
     * @param dto
     * @return
     */
    @PostMapping("/getNextNodeUser")
    public Result<List<NextAuditUserVo>> getNextNodeUser(@Validated @RequestBody AuditNextUserQueryDto dto){
        return Result.success("success",caseApprovalWaitRecordService.getNextNodeUser(dto));
    }


    /**
     * 查询待审批列表审批事项（文书种类）
     * @param
     * @return
     */
    @PostMapping("/getAuditItemList")
    public Result<List<AuditItemVo>> getAuditItemList(){
        // 查询文书类别表
        return Result.success("success",caseApprovalWaitRecordService.getAuditItemList());
    }
    /**
     * 获取审批相关状态
     * @author liyafeng
     * @date 2022/8/9
     * @param approvalQueryDto
     * @return {@link Result< String>}
     */
    @PostMapping("/getApprovalInfo")
    public Result<ApprovalInfoVo> getApprovalInfo(@Validated @RequestBody ApprovalQueryDto approvalQueryDto){
        ApprovalInfoVo vo=caseApprovalWaitRecordService.getApprovalInfo(approvalQueryDto);
        return Result.success("success",vo);
    }
    /**
     * 审批通过(裁执分离)
     * @param
     * @return
     */
    @PostMapping("/doAgreeAuditWithExecute")
    public Result doAgreeAuditWithExecute(@Validated @RequestBody ApprovalAgreeAuditDto approvalAuditDto){
        //读取当前用户，当前审批环节，校验角色权限，根据审批结果，流转下个节点
        // 校验审批权限 （不做了，能查到，数据存入时已校验处理）
        // 审批结果写入 case_approval_complete_record 已完成审批表 ，
        // 审批通过 写入下个节点  写入 待审批 case_approval_wait_record
        // 中间需要调用member服务 查询审批人姓名
        if(caseApprovalWaitRecordService.doAgreeAuditWithExecute(approvalAuditDto).size() == 1){
            return Result.success("操作成功！");
        }
        String ugl = "unGetLock";
        if (caseApprovalWaitRecordService.doAgreeAuditWithExecute(approvalAuditDto).get(ugl) != null){
            return Result.error(caseApprovalWaitRecordService.doAgreeAuditWithExecute(approvalAuditDto).get(ugl).toString());
        }

        return Result.error("操作失败！");
    }
    /**
     * 审批退回(裁执分离)
     * @param
     * @return
     */
    @PostMapping("/doReturnAuditWithExecute")
    public Result doReturnAuditWithExecute(@Validated @RequestBody ApprovalReturnlAuditDto approvalAuditDto){
        //读取当前用户，当前审批环节，校验角色权限，根据审批结果，流转下个节点
        // 校验审批权限 （不做了，能查到，数据存入时已校验处理）
        // 审批结果写入 case_approval_complete_record 已完成审批表，
        // 审批通过 写入下个节点  写入 待审批 case_approval_wait_record
        // 中间需要调用member服务 查询审批人姓名
        if(caseApprovalWaitRecordService.doReturnAuditWithExecute(approvalAuditDto).size() >= 1){
            return Result.success("操作成功！");
        }

        String ugl = "unGetLock";
        if (caseApprovalWaitRecordService.doReturnAuditWithExecute(approvalAuditDto).get(ugl) != null){
            return Result.error(caseApprovalWaitRecordService.doReturnAudit(approvalAuditDto).get(ugl).toString());
        }
        return Result.error("操作失败！");
    }
    /**
     * 速结程序查询当前审批信息
     * @param
     * @return
     */
    @PostMapping("/getFastCaseApprovalInfo")
    public Result<FastCaseApprovalInfoVo> getFastCaseApprovalInfo(@Validated @RequestBody FastCaseApprovalDto dto){
        FastCaseApprovalInfoVo vo = caseApprovalWaitRecordService.getFastCaseApprovalInfo(dto.getCaseId(),dto.getDocumentCatalogCode());
        return Result.success("操作成功！",vo);
    }
    /**
     * 速结程序查询是否审批完成
     * @param
     * @return
     */
    @PostMapping("/getFastCaseIsApprovalPass")
    public Result<String> getFastCaseIsApprovalPass(@Validated @RequestBody FastCaseApprovalDto dto){
        String isApprovalPass=cfRedisRepository.get("IS_APPROVAL_AUTO_PASS"+dto.getCaseId());
        return Result.success("操作成功！",isApprovalPass);
    }

    /**
     * 获取工作台统计数据
     * @param dto
     * @return
     */
    @PostMapping("/getWorkbenchStatistics")
    public Result<WorkbenchStatisticsJsonVo> getWorkbenchStatistics(@RequestBody WorkbenchStatisticsDto dto){
        WorkbenchStatisticsJsonVo workbenchStatisticsVo = caseApprovalWaitRecordService.getWorkbenchStatistics(dto);
        return Result.success(workbenchStatisticsVo);
    }

    /**
     * 获取个人代办任务
     * @param personalTaskDto
     * @return
     */
    @PostMapping("/getPersonalTask")
    public Result<PageResponse<PersonalTaskVo>> getPersonalTask(@RequestBody PersonalTaskDto personalTaskDto){
        List<PersonalTaskVo> personalTask = caseApprovalWaitRecordService.getPersonalTask(personalTaskDto);
        return Result.success(new PageResponse<>(personalTask));
    }
    /**
     * 审批是否展示公示详情 1 是 , 0 否
     * @author liyafeng
     * @date 2022/12/22
     * @param dto
     * @return {@link Result< String>}
     */
    @PostMapping("/getApprovalIsShowPublicDetail")
    public Result<String> getApprovalIsShowPublicDetail(@Validated @RequestBody  ApprovalIsShowPublicDetailDto dto) {
        String isShow=caseApprovalWaitRecordService.getApprovalIsShowPublicDetail(dto);
        return Result.success("获取成功",isShow);
    }
    /**
     * 是否展示去设置 1是，0否
     * @author liyafeng
     * @date 2023/2/1
      * @param
     * @return {@link Result< String>}
     */
    @PostMapping("/getApprovalIsShowSetPerson")
    public Result<String> getApprovalIsShowSetPerson() {
        UserDTO userDTO=UserUtil.getUserInfo();
        String userId=userDTO.getUserId().toString();
        String orgCode=userDTO.getOrgCode();
        String isShow=caseApprovalWaitRecordService.getApprovalIsShowSetPerson(userId,orgCode);
        return Result.success("获取成功",isShow);
    }
    /**
     * 合并提交审批接口，该文书需要审批调用（简案快办合并提交使用）
     * @author liyafeng
     * @date 2023/4/24
      * @param dto
     * @return {@link Result}
     */
    @PostMapping("/documentGeneralMergeSubmit")
    public Result documentGeneralMergeSubmit(@Validated @RequestBody ApprovalGeneralSubmitDto dto){
        cfRedisRepository.set("IS_APPROVAL_AUTO_PASS"+dto.getCaseId(),"false");
        Map<String,Object> result = caseApprovalWaitRecordService.documentGeneralSubmitMergeAuto(dto);
        String closeSignal= MapUtils.getString(result,"closeSignal","");
        if(!"CLOSE-TRIGGER-APPROVAL".equals(closeSignal)){
            Result.error("操作失败！");
        }
        ApprovalAgreeAuditDto approvalAgreeAuditDto = caseApprovalWaitRecordService.getApprovalAgreeAuditMergeDto(dto);
        //approvalAgreeAuditDto.setNowHandler(dto.getNextHandler());
        for (int i=0;i<4;i++) {
            //如果下个环节是自动审批
            approvalAgreeAuditDto.setDocumentCatalogCode(dto.getDocumentCatalogCode());
            approvalAgreeAuditDto.setIsMerge(dto.getIsMerge());
            if(Constant.STRING_1.equals(approvalAgreeAuditDto.getIsAutoApproval())) {
                Long autoTime = Long.valueOf(approvalAgreeAuditDto.getAutoTime());
                if(autoTime>2){
                    autoTime=autoTime-2;
                }
                try {
                    Thread.sleep(autoTime * 1000);
                    Map<String, Object> agreeResult = caseApprovalWaitRecordService.doAgreeAuditMergeAuto(approvalAgreeAuditDto);
                    closeSignal = MapUtils.getString(agreeResult, "closeSignal", "");
                    result.put("closeSignal", "CLOSE-TRIGGER-APPROVAL-PASS");
                    if ("CLOSE-TRIGGER-APPROVAL-PASS".equals(closeSignal)) {
                        cfRedisRepository.set("IS_APPROVAL_AUTO_PASS" + dto.getCaseId(), "true");
                        break;
                    }
                    String nowHandler = approvalAgreeAuditDto.getNextHandler();
                    approvalAgreeAuditDto = caseApprovalWaitRecordService.getApprovalAgreeAuditMergeDto(dto);
                    approvalAgreeAuditDto.setNowHandler(nowHandler);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }else{
                cfRedisRepository.set("IS_APPROVAL_AUTO_PASS"+dto.getCaseId(),"true");
                break;
            }
        }
        return Result.success("操作成功！",result);
    }

    /**
     * 审批通过（合并审批）
     * @param
     * @return
     */
    @PostMapping("/doAgreeAuditMerge")
    public Result doAgreeAuditMerge(@Validated @RequestBody ApprovalAgreeAuditDto approvalAuditDto){
        //读取当前用户，当前审批环节，校验角色权限，根据审批结果，流转下个节点
        // 校验审批权限 （不做了，能查到，数据存入时已校验处理）
        // 审批结果写入 case_approval_complete_record 已完成审批表 ，
        // 审批通过 写入下个节点  写入 待审批 case_approval_wait_record
        // 中间需要调用member服务 查询审批人姓名
        caseApprovalWaitRecordService.doAgreeAuditMerge(approvalAuditDto);
        return Result.success("操作成功！");


      /*  String ugl = "unGetLock";
        if (caseApprovalWaitRecordService.doAgreeAudit(approvalAuditDto).get(ugl) != null){
            return Result.error(caseApprovalWaitRecordService.doAgreeAudit(approvalAuditDto).get(ugl).toString());
        }*/
    }

    /**
     * 审批退回(合并审批)
     * @param
     * @return
     */
    @PostMapping("/doReturnAuditMerge")
    public Result doReturnAuditMerge(@Validated @RequestBody ApprovalReturnlAuditDto approvalAuditDto){
        //读取当前用户，当前审批环节，校验角色权限，根据审批结果，流转下个节点
        // 校验审批权限 （不做了，能查到，数据存入时已校验处理）
        // 审批结果写入 case_approval_complete_record 已完成审批表，
        // 审批通过 写入下个节点  写入 待审批 case_approval_wait_record
        // 中间需要调用member服务 查询审批人姓名
        if(caseApprovalWaitRecordService.doReturnAuditMerge(approvalAuditDto).size() >= 1){
            return Result.success("操作成功！");
        }

       /* String ugl = "unGetLock";
        if (caseApprovalWaitRecordService.doReturnAudit(approvalAuditDto).get(ugl) != null){
            return Result.error(caseApprovalWaitRecordService.doReturnAudit(approvalAuditDto).get(ugl).toString());
        }*/
        return Result.error("操作失败！");
    }

}
